(function (window, $) {
  var search = {
    init: function () {
      this.cacheElment();
      this.bindEvent();
    },
    cacheElment: function () {
      this.$table = '';
    },
    bindEvent: function () {
      this.initSearch();
      // 查询结果查看详情
      $("#searchTable").on("click", ".search-text", this.textDetailFn);
      $("#searchTable").on("click", ".search-url", this.urlDetailFn);
      //  查询
      $(".searchList").on("click", ".icon-search", this.searchFn);
      // 输入框回车搜索
      $(".searchList").on("keydown", ".search-inp", this.entrySearchFn);

    },
    initSearch: function () {
      var data = [{
        id: '001',
        text: '关于SupFire神火手电筒包装和标识变更通知',
        url: 'http://www.supfire.com/news/36-cn.htm'
      }, {
        id: '002',
        text: '关于SupFire神火手电筒包装和标识变更通知',
        url: 'http://www.supfire.com/news/36-cn.htm'
      }, {
        id: '003',
        text: '关于SupFire神火手电筒包装和标识变更通知',
        url: 'http://www.supfire.com/news/36-cn.htm'
      }]
      search.$table = $('#searchTable').DataTable({
        searching: false,
        bInfo: false,
        ordering: false,
        autoWidth: false,
        lengthChange: false,
        iDisplayLength: 6, // 每页显示行数
        language: {
          "paginate": {
            "previous": "上一页",
            "next": "下一页"
          }
        },
        "data": data,
        // ajax: {
        //   url: "",
        //   data: $(".search-inp").val()
        // },
        columns: [
          {
            data: "imageUrl",
            width: "100px",
            className: "date",
            render: function (data, type, row, meta) {
              var str = '<div class="search-item">' +
                '<a href="#" data-id=' + row.id + ' class="search-text">' +
                '<h3>' + row.text + '</h3>' +
                '</a>' +
                '<a href="#" data-id=' + row.id + ' class="search-url">' + row.url + '</a>' +
                '</div>';
              return str;
            }
          }]
      });
    },
    searchFn: function () {
      search.$table.draw();
    },
    textDetailFn: function () {
      // TODO 根据不同的搜索id去查看对应的搜索详情
      var id = $(this).data("id");
      // window.location.href = "newDetail.html";
    },
    urlDetailFn: function () {
      // TODO 根据不同的搜索id去查看对应的搜索详情
      var id = $(this).data("id");
      // window.location.href = "newDetail.html";
    },
    entrySearchFn: function () {
      var evt = window.event || e;
      if (evt.keyCode == 13) {
        search.searchFn();
      }
    }
  }
  search.init();
})(window, jQuery);